package com.earnings.okhttputils.utils.adapter;

import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.bean.LoveDetailData;
import com.earnings.okhttputils.utils.god.GodAdapter.GodBaseAdapter;
import com.earnings.okhttputils.utils.god.GodAdapter.GodViewHolder;
import com.earnings.okhttputils.utils.utils.TimestampTransform;

/**
 * Created by Administrator on 2017/5/9 0009.
 */

public class LoveDetailAdapter extends GodBaseAdapter<LoveDetailData> {
    public LoveDetailAdapter(int layoutId) {
        super(layoutId);
    }

    @Override
    public void onBind(GodViewHolder holder, int position, LoveDetailData data) {
        //    "type":1		//类型（1，2为补贴金获得爱心，3为补贴满300元）
        //UI右边
        holder.getView(R.id.time_tv).setVisibility(View.VISIBLE);
        holder.getView(R.id.right_root_view).setVisibility(View.GONE);
        //UI左边
        holder.getView(R.id.detail_time_tv).setVisibility(View.GONE);
        holder.getView(R.id.love_root_view).setVisibility(View.VISIBLE);

        //第一条顶部阴影
        if (position == 0) {
            holder.getView(R.id.item_top_view).setVisibility(View.VISIBLE);
        }

        if (data.getType().equals("1") || data.getType().equals("2")) {
            holder.setImageResource(R.id.icon_img, R.mipmap.lanxin);
        } else {
            holder.setImageResource(R.id.icon_img, R.mipmap.hongxin);
        }

        holder.setText(R.id.name_tv, data.getTypemsg());
        double greenchange = Double.parseDouble(data.getGreenchange());
        double bluechange = Double.parseDouble(data.getBluechange());
        double redchange = Double.parseDouble(data.getRedchange());
        double bluesleepchange = Double.parseDouble(data.getBluesleepchange());

        String symbol = "";
        //红心
        if (redchange > 0) {
            holder.setTextColor(R.id.rad_tv, R.color.green);
            symbol = "+";
        }
        if (redchange < 0) {
            holder.setTextColor(R.id.rad_tv, R.color.rad);

        }
        if (redchange == 0) holder.getView(R.id.rad_tv).setVisibility(View.GONE);

        //绿心
        if (greenchange > 0) {
            holder.setTextColor(R.id.green_tv, R.color.green);
            symbol = "+";
        }
        if (greenchange < 0) {
            holder.setTextColor(R.id.green_tv, R.color.rad);

        }
        if (greenchange == 0) holder.getView(R.id.green_tv).setVisibility(View.GONE);

        //蓝心
        if (bluechange > 0) {
            holder.setTextColor(R.id.blue_tv, R.color.green);
            symbol = "+";
        }
        if (bluechange < 0) {
            holder.setTextColor(R.id.blue_tv, R.color.rad);
        }
        if (bluechange == 0) holder.getView(R.id.blue_tv).setVisibility(View.GONE);

        //休眠蓝心
        if (bluesleepchange > 0) {
            holder.setTextColor(R.id.bluesleep_tv, R.color.green);
            symbol = "+";
        }
        if (bluesleepchange < 0) {
            holder.setTextColor(R.id.bluesleep_tv, R.color.rad);
        }
        if (bluesleepchange == 0) holder.getView(R.id.bluesleep_tv).setVisibility(View.GONE);

        holder.setText(R.id.blue_tv, "蓝心" + symbol + bluechange);
        holder.setText(R.id.rad_tv, "红心" + symbol + redchange);
        holder.setText(R.id.green_tv, "绿心" + symbol + greenchange);
        holder.setText(R.id.bluesleep_tv, "休眠蓝心" + symbol + bluesleepchange);

        //时间
        String time = TimestampTransform.getYMD(data.getCreatetime());
        holder.setText(R.id.time_tv, time);

    }
}
